#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

enum NodeType
{
  ATOM,
  LIST
};

typedef struct glist
{
  NodeType nodeType;
  union
  {
    char value;
    struct glist *list;
  }a;
  struct glist *next;    
}GList;

GList* sAlloc()
{
  GList *p =  (GList *)malloc(sizeof(GList));
  if(p == NULL) 
    {
      exit(1);
      return NULL;
    }
  memset(p,0,sizeof(GList));
  return p;
}

void create(GList* *p)
{
  //  GList *p;// = head;
  char c;
  while(scanf("%c",&c) != EOF)
    {
      switch(c)
        {
        case '(':
          *p = sAlloc();          
          (*p) -> nodeType = LIST;
          create(&((*p) -> a.list));
          break;
        case ')':
          //          p -> next = NULL;
          (*p) = NULL;
          return;
          
        case ' ':
          break;

        case '\r':
        case '\n':
          break;
          
        default:
          *p = sAlloc();
          (*p) -> nodeType = ATOM;
          (*p) -> a.value = c;
          create(&((*p) -> next));
          break;
        }
    }
}

void print(GList *p)
{
  if(p == NULL)
    return;
  if(p -> nodeType == ATOM)  
    {
      printf("%c",p -> a.value);
      print(p -> next); 
    }
  else if(p -> nodeType == LIST)   
    {
      printf("(");
      print(p -> a.list);
      printf(")");
    }
}

int main() 
{ 

#ifdef FILEIO
  freopen("in.txt","r",stdin); 
  freopen("out.txt","w",stdout); 
#endif

  char c;
  int matched = 0;

//   GList *head = sAlloc();
//   GList *p = head;
//   head -> nodeType = LIST;
  GList *head;

  create(&head);
  print(head);
  //   if(matched > 0)
  //     {
  //       printf("no match\n");
  //     }
  //   else
  //     printf("match\n");


#ifdef FILEIO
  fclose(stdin);
  fclose(stdout);
#endif
  
  return 0; 
} 
